// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class STUDY_PHASE_CSU_C11 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("21 CSP",21)]
  	    [HL7Field(HL7Version.v23, 21, HL7Repeat.False, HL7Required.False,"CSP")]
	    public CSP CSP {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("23 STUDY_SCHEDULE",23)]
  	    [HL7Field(HL7Version.v23, 23, HL7Repeat.True, HL7Required.True,"STUDY_SCHEDULE_CSU_C11")]
	    public STUDY_SCHEDULE_CSU_C11[] STUDY_SCHEDULE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("38 STUDY_PHARM",38)]
  	    [HL7Field(HL7Version.v23, 38, HL7Repeat.True, HL7Required.True,"STUDY_PHARM_CSU_C11")]
	    public STUDY_PHARM_CSU_C11[] STUDY_PHARM {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			CSP = PopSegmentParseAndCheckRequired<CSP>(availableData, options, "CSP");
			STUDY_SCHEDULE = ProcessGroupArray<STUDY_SCHEDULE_CSU_C11>(availableData, options, "STUDY_SCHEDULE");
			STUDY_PHARM = ProcessGroupArray<STUDY_PHARM_CSU_C11>(availableData, options, "STUDY_PHARM");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isCSP = availableData.StartsWith("CSP", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("CSP", options.Version) || isCSP) {
				return isCSP;
			}
			STUDY_SCHEDULE_CSU_C11 testSTUDY_SCHEDULE_CSU_C11 = new STUDY_SCHEDULE_CSU_C11();
			bool grpCCSTUDY_SCHEDULE_CSU_C11 = (testSTUDY_SCHEDULE_CSU_C11.CanConsume(availableData, options));
			if (IsRequired("STUDY_SCHEDULE", options.Version) || grpCCSTUDY_SCHEDULE_CSU_C11) {
				return grpCCSTUDY_SCHEDULE_CSU_C11;
			}
			STUDY_PHARM_CSU_C11 testSTUDY_PHARM_CSU_C11 = new STUDY_PHARM_CSU_C11();
			bool grpCCSTUDY_PHARM_CSU_C11 = (testSTUDY_PHARM_CSU_C11.CanConsume(availableData, options));
			if (IsRequired("STUDY_PHARM", options.Version) || grpCCSTUDY_PHARM_CSU_C11) {
				return grpCCSTUDY_PHARM_CSU_C11;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "STUDY_PHASE";
			}
        }

        static STUDY_PHASE_CSU_C11() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(STUDY_PHASE_CSU_C11));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (CSP != null) {
			string segmentValue = CSP.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (STUDY_SCHEDULE != null && STUDY_SCHEDULE.Length > 0) {
			for (int i = 0; i < STUDY_SCHEDULE.Length; i++) {
				string segmentValue = STUDY_SCHEDULE[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (STUDY_PHARM != null && STUDY_PHARM.Length > 0) {
			for (int i = 0; i < STUDY_PHARM.Length; i++) {
				string segmentValue = STUDY_PHARM[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

